import {Component} from '@angular/core';
import {NavController, IonicPage} from 'ionic-angular';
import {AppService, AppGlobal} from "../../app/app.service";

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  // 接收数据用
  listData: Object;

  slides: Array<any> = [];
  //categories: Array<any> = [];
  products: Array<any> = [];

  //加载标志
  spinner1: boolean = true;
  productflg: boolean = true;
  params = {
    pageNo: 1,
    pageSize: 20
  };

  constructor(public appService: AppService, public navCtrl: NavController) {
    this.getSlides();
    //this.getCategories();
    this.getProducts();
  }

  //获取幻灯片
  getSlides() {
    var params = {pageNo: 1, pageSize: 5}
    this.appService.httpGet(AppGlobal.API.getRepository, params, rs => {
      console.debug(rs);
      this.slides = rs.data;
      //this.categories = rs.data;
      this.spinner1 = false;
    })
  }

/*获取幻灯片
  getSlides() {
    var params = {pageNo: 1, pageSize: 5}
    this.appService.httpGet(AppGlobal.API.getProducts, params, rs => {
      console.debug(rs);
      this.slides = rs.data;
      this.categories = rs.data;
      this.spinner1 = false;
    })
  }
*/
/*获取分类
  getCategories() {
    this.appService.httpGet(AppGlobal.API.getProducts, {pageNo: 1, pageSize: 2}, rs => {
      console.debug(rs);
      this.categories = rs.data;
    })
  }
*/
//获取首页推荐列表
  getProducts() {
    this.appService.httpGet(AppGlobal.API.getRepositorytype, this.params, rs => {
      console.debug(rs);
      this.products = rs.data;
      this.productflg = false;
    })
  }

//知识库详情
  goDetails(item) {
    console.debug('go details...')
    this.navCtrl.push('RepositoryDetailsPage',{item:item});
  }
/*
  ionViewDidLoad() {
    this.http.request('http://jsonplaceholder.typicode.com/photos').subscribe((res: Response) => {
      this.listData = res.json();
    });
  }
*/
/*
  goCategorie(item) {
    console.debug(item)
    if (item && item != '' && item.id== '1'){
      this.navCtrl.push('RepositoryPage', { item: item });
    } else {
      this.navCtrl.push('CustomerPage', { item: item });
    }

  }
  */
}
